<template>
  <div>
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane v-if="showDraftTabs" label="草稿库" name="first">
        <DraftTable ref="DraftTable" @released="refreshDraftTable"></DraftTable>
      </el-tab-pane>

      <el-tab-pane v-if="showOfficialTabs" label="正式库" name="second">
        <OfficialTable ref="OfficialTable" :showStatus="this.isShow"
                       @cancelReleased="refreshOfficialTable"></OfficialTable>
      </el-tab-pane>

      <el-tab-pane v-if="showPushTabs" label="推送" name="third">
        <PushTable ref="PushTable"></PushTable>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import DraftTable from "../book/DraftTable";
import OfficialTable from "../book/OfficialTable";
import PushTable from "./PushTable";

export default {
  name: "BookLib",
  components: {
    PushTable,
    DraftTable,
    OfficialTable
  },
  data() {
    return {
      activeName: 'first',
      showDraftTabs: true,
      showOfficialTabs: true,
      showPushTabs: true,
      isShow: ''
    };
  },
  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    },
    refreshDraftTable() {
      this.$refs.OfficialTable.getTableData()
      this.$refs.PushTable.advanceConfirm()
    },
    refreshOfficialTable() {
      this.$refs.DraftTable.getTableData()
      this.$refs.PushTable.advanceConfirm()
    },
  },
  created() {

    if (this.$store.state.user.userName === 'admin') {

      this.isShow = 'false'
      return
    }
    //角色Id等于管理员角色
    for (let i = 0; i < this.$store.state.user.roleIds.length; i++) {
      if (this.$store.state.user.roleIds[i] === '1455781731549327361') {
        this.isShow = 'false'
        return;
      }
    }
    UTIL.findTreeNode(this.$store.state.menuList, item => {
      if (item.id === this.$store.state.activeId) {
        if (item.editButton || item.detailButton) {
          this.showPushTabs = false
          if (item.editButton && item.detailButton) {
            this.isShow = 'false'
          } else {
            if (item.detailButton) {
              this.showDraftTabs = false
              this.showPushTabs = false
              this.activeName = 'second'
              this.isShow = "true"
            }
          }
        }
        if (item.editButton && item.pushButton) {
          this.showDraftTabs = true
          this.showOfficialTabs = true
          this.showPushTabs = true
        } else {
          if (item.detailButton && item.pushButton) {
            this.activeName = 'second'
            this.showDraftTabs = false
            this.showOfficialTabs = true
            this.showPushTabs = true
          } else {
            if (item.pushButton) {
              this.showDraftTabs = false
              this.showOfficialTabs = false
              this.activeName = 'third'
            }
          }
        }
      }
    })
  }
}
</script>

<style scoped>

</style>
